package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
	"time"
)

type Article struct {
	ent.Schema
}

func (Article) Fields() []ent.Field {
	return []ent.Field{
		field.Int("id"),
		field.Int("user_id").Optional().Default(0),
		field.Int("category").Default(0),
		field.String("title").Default(""),
		field.String("summary").Default(""),
		field.String("content").Default(""),
		field.Int("read_count").Default(0),
		field.Int("price").Default(0),
		field.Int("sale_count").Default(0),
		field.Time("create_time").Default(time.Now),
		field.Time("update_time").Default(time.Now).UpdateDefault(time.Now),
	}
}

func (Article) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("User", User.Type).
			Ref("articles").Field("user_id").
			Unique(),
		edge.To("orders", ArticleOrder.Type),
	}
}
